package com.moorror.codegenvel.view.window.codegen.domain;

import com.moorror.codegenvel.common.table.AColumnDesc;
import com.moorror.codegenvel.common.table.ColumnShowAttr;
import com.moorror.codegenvel.common.table.bean.AbstractTableStringRow;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.compress.utils.Lists;

import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

/**
 * @Author jiyanghuang
 * @Date 2025/8/25 21:53
 */
public class ExtractVariableColumn extends AbstractTableStringRow<ExtractVariableColumn> {

    @Getter
    @Setter
    @AColumnDesc(nameShow = "VariableVelocity", order = 1, columnShowAttr = ColumnShowAttr.KEY_VALUE)
    private String varVelocity;

    @Getter
    @Setter
    @AColumnDesc(nameShow = "VariableReplace", order = 2, vcFun = "updateValue")
    private String varReplace;

    private BiConsumer<ExtractVariableColumn, ExtractVariableColumn> updateConsumer;

    public static List<ExtractVariableColumn> ofMock(){
        List<ExtractVariableColumn> list = Lists.newArrayList();
        ExtractVariableColumn tableSQLColumn = new ExtractVariableColumn();
        tableSQLColumn.setVarVelocity("one");
        tableSQLColumn.setVarReplace("replace");
        list.add(tableSQLColumn);

        tableSQLColumn = new ExtractVariableColumn();
        tableSQLColumn.setVarVelocity("one2");
        tableSQLColumn.setVarReplace("replace2");
        list.add(tableSQLColumn);

        return list;
    }

    public static List<ExtractVariableColumn> genTableData(List<Map.Entry<String, String>> strings, BiConsumer<ExtractVariableColumn, ExtractVariableColumn> updateConsumer) {
        List<ExtractVariableColumn> rows = Lists.newArrayList();
//        for (int i = 0; i < strings.size(); i++) {
//            TableSQLColumn redisListRow = new TableSQLColumn();
//            Map.Entry<String, String> entry = strings.get(i);
//            redisListRow.setRow(i);
//            redisListRow.setValue(entry.getValue());
//            redisListRow.setField(entry.getKey());
//            redisListRow.setTypeEnum(typeEnum);
//            redisListRow.setUpdateConsumer(updateConsumer);
//            rows.add(redisListRow);
//        }
        return rows;
    }

    public void updateValue(ExtractVariableColumn old, ExtractVariableColumn update) {
        if(null != updateConsumer){
            updateConsumer.accept(old, update);
        }
    }


    @Override
    public ExtractVariableColumn copyThis() {
        ExtractVariableColumn redisListRow = new ExtractVariableColumn();
        redisListRow.setVarVelocity(this.getVarVelocity());
        redisListRow.setVarReplace(this.getVarReplace());
        return redisListRow;
    }

    @Override
    public ExtractVariableColumn newRowDefault() {
        this.setVarVelocity("velocity");
        this.setVarReplace("replace");
        return this;
    }



    public BiConsumer<ExtractVariableColumn, ExtractVariableColumn> getUpdateConsumer() {
        return updateConsumer;
    }

    public void setUpdateConsumer(BiConsumer<ExtractVariableColumn, ExtractVariableColumn> updateConsumer) {
        this.updateConsumer = updateConsumer;
    }
}
